var app = getApp();
var ischoosed =0
import Toast from '@vant/weapp/toast/toast'
const schools = {
  南昌工程学院: ['彭桥校区', '瑶湖校区'],
  延边大学: ['延吉校区', '珲春校区'],
  内蒙古师范大学: ['赛罕校区', '盛乐校区'],
  江西师范大学: ['瑶湖校区', '青山湖校区'],
  江西科技学院: ['瑶湖校区', '京东校区'],
};

Page({

  /**
   * 页面的初始数据
   */
  data: {
    columns: [
      {
        values: Object.keys(schools),
        className: 'column1',
      },
      {
        values: schools['南昌工程学院'],
        className: 'column2',
        defaultIndex: 0,
      },
    ],
    show:false,
    tabbar: {},
    adPositionIndexPop:false,
    school:"选择校区 >",
    mySchoolName:"",
    mylocationName:""
  },
  sendkd(){
    if(wx.getStorageSync("schoolName"))
    {
      wx.navigateTo({
        url: "/pages/sendmsg/sendmsg?tapIdx=0",
      })
    }
    else{
      wx.showToast({
        icon:"error",
        title: '请先选择校区',
      })
      this.setData({ show: true });
    }
    
  },
  sendwm(){
    if(wx.getStorageSync("schoolName"))
    {
      wx.navigateTo({
        url: "/pages/sendmsg/sendmsg?tapIdx=1",
      })
    }
    else{
      wx.showToast({
        icon:"error",
        title: '请先选择校区',
      })
      this.setData({ show: true });
    }
    
  },
  sendty(){
    if(wx.getStorageSync("schoolName"))
    {
      wx.navigateTo({
        url: "/pages/sendmsg/sendmsg?tapIdx=2",
      })
    }
    else{
      wx.showToast({
        icon:"error",
        title: '请先选择校区',
      })
      this.setData({ show: true });
    }
   
  },
  getmsg(){
    if(wx.getStorageSync("schoolName"))
    {
      wx.navigateTo({
        url: "/pages/getmsg/getmsg" ,
      })
    }
    else{
      wx.showToast({
        icon:"error",
        title: '请先选择校区',
      })
      this.setData({ show: true });
    }
  },
  onChange(event) {
    const { picker, value, index } = event.detail;
    picker.setColumnValues(1, schools[value[0]]);
  },
  onConfirm(event) {
    const { picker, value, index } = event.detail;
    app.globalData.locationNum = event.detail.index
    app.globalData.locationName=event.detail.value
    wx.setStorage({ key: "locationNum", data: event.detail.index});
    wx.setStorage({ key: "schoolName", data: event.detail.value[0]});
    wx.setStorage({ key: "locationName", data: event.detail.value[1]});
    this.setData({ 
      show: false,
      mySchoolName:event.detail.value[0],
      mylocationName:event.detail.value[1]
    });
  },
  onCancel() {
    this.setData({ show: false });
  },  
  showPopup() {
    this.setData({ show: true });
  },

  closeAdPositionIndexPop() {
    this.setData({
      adPositionIndexPop: false
    })
  },
  clickAdPositionIndexPop() {
    this.setData({
      adPositionIndexPop: false
    })
    wx.navigateTo({
      url: '/pages/getsalecard/getsalecard',
    })
  },
  goCoupons(){
    wx.navigateTo({
      url: '/pages/getsalecard/getsalecard',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      navHeight: app.globalData.navHeight,
      navTop: app.globalData.navTop,
      windowHeight: app.globalData.windowHeight,
      menuButtonObject: app.globalData.menuButtonObject //小程序胶囊信息
    })
    let ischeckSchool = wx.getStorageSync("locationName");
    if(ischeckSchool){
      this.setData({
        mySchoolName:ischeckSchool[0],
        mylocationName:ischeckSchool[1]
      })
      app.globalData.schoolName = ischeckSchool[0]
      app.globalData.locationName = ischeckSchool[1]
    }
    // app.globalData.locationNum=this.data.option1[0].value
    // app.globalData.locationName=this.data.option1[0].text
    // wx.setStorage({ key: "locationNum", data: this.data.option1[0].value});
    // wx.setStorage({ key: "locationName", data: this.data.option1[0].text});
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let touxiang = wx.getStorageSync("touxiang");
    let userInfoName = wx.getStorageSync("userInfoName");
    if(!userInfoName)
    {
      wx.navigateTo({
      url: '/pages/login/login',
     }) 
    }
    else{
      app.globalData.userInfoName=userInfoName
      app.globalData.touxiang=touxiang
      app.globalData.userInfo=touxiang
    }
    
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
    this.getTabBar().setData({
      selected: 0    // 根据tab的索引值设置
    }) 
  }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})